﻿using System;

using Microsoft.StyleCop;
using Microsoft.StyleCop.CSharp;

namespace StyleCopContrib.CSharp.Rules
{
	internal class SpacingRules
	{
		internal static void CheckTabsMustBeUsed(CodeElement element,
			Node<CsToken> node,
			DocumentAnalyzer context)
		{
			var token = node.Value;
			if (token.CsTokenType == CsTokenType.WhiteSpace)
			{
				var whitespace = (Whitespace)token;
				if (node.Previous == null ||
					node.Previous.Value.CsTokenType == CsTokenType.EndOfLine)
				{
					if (whitespace.SpaceCount > 0)
					{
						context.AddViolation(element, token.LineNumber, RuleNames.TabsMustBeUsed);
					}
				}
			}
		}
	}
}
